//
//  UITableView+Helper.m
//  lvfj
//
//  Created by lvfeijun on 2019/12/27.
//  Copyright © 2019 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//

#import "UITableView+Helper.h"

@implementation UITableView (Helper)
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
//        _tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15);
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        //分割线
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = [UIColor clearColor];
        
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(self.view);
        }];
    }
    return _tableView;
}
-(UITableViewCell *)getCellFromIndexPath:(NSIndexPath *)indexPath{
    return [self cellForRowAtIndexPath:indexPath];
}

-(void)hiddenScrollIndicator{
    //隐藏滑块
    self.showsVerticalScrollIndicator = NO;
    self.showsHorizontalScrollIndicator = NO;
}
-(void)setScrollIndicatorStyle:(UIScrollViewIndicatorStyle )style{
    //设置滑块样式
    self.indicatorStyle = style;
}

//去除 UITableViewStyleGrouped 的间隙
- (instancetype)init
{
    self = [super init];
    if (self) {
        self = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        self.sectionFooterHeight = 0;
        // 去掉 iOS 15的UITableViewStylePlain 顶部间距
        if (@available(iOS 15.0,*)) {//UITableViewStylePlain
            self.sectionHeaderTopPadding = YES;
        }
    }
    return self;
}

//没有横线 去除tableview 横线
-(void)setNoneLine{
    //分割线
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
}

/*
 ####错误代码展示
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     ATableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ATableViewCell class]) forIndexPath:indexPath];
     __weak typeof(self) weakSelf = self;
     cell.delegateBlock = ^(UIButton * _Nonnull btn) {
         [weakSelf.datas removeObject:self.datas[indexPath.row]];
         [weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
     };
     cell.textLabel.text = [NSString stringWithFormat:@"(0,%@)",self.datas[indexPath.row]];
     
     return cell;
 }
 正确代码展示
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     ATableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ATableViewCell class]) forIndexPath:indexPath];
     __weak typeof(self) weakSelf = self;
     cell.delegateBlock = ^(UIButton * _Nonnull btn) {
         CGPoint point = [btn convertPoint:btn.bounds.origin toView:tableView];
         NSIndexPath *newIndexPath = [tableView indexPathForRowAtPoint:point];
         [weakSelf.datas removeObject:self.datas[newIndexPath.row]];
         [weakSelf.tableView deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationRight];
     };
     cell.textLabel.text = [NSString stringWithFormat:@"(0,%@)",self.datas[indexPath.row]];
     
     return cell;
 }
*/
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //点击后恢复 非高亮 状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}

/*
    if (indexPath.row) {
//           if (!_SelctColletionViewCell) {//重用机制导致数据错位
                 _SelctColletionViewCell=[tableView dequeueReusableCellWithIdentifier:@"cell2"];
                _SelctColletionViewCell.hiddenShenSha = YES;
                 _SelctColletionViewCell.delegate=self;
                 _SelctColletionViewCell.mp=_mpDataSouce;
               _SelctColletionViewCell.duibi = YES;
               _SelctColletionViewCell.isTwo = self.isTwo;
//             }
         return _SelctColletionViewCell;
       }else{//0
//           if (!_headInfCell) {
              _headInfCell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
               _headInfCell.hiddenShenSha = YES;
              _headInfCell.delegate = self;
//           }
           _headInfCell.isTwo = self.isTwo;
           self.headInfCell.titleLb.font = [UIFont systemFontOfSize:self.isTwo?12:16];
           _headInfCell.mp = self.mpDataSouce;
           _headInfCell.titleLb.text = self.data.f_name;
           _headInfCell.TimeUnknow=[self.data.unknown intValue];
          return _headInfCell;
       }
*/

@end
